{extend name="adminblue/base" /}
{block name="resources"/}
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
<link href="__STATIC__/blue/css/order/ns_orderlist.css" rel="stylesheet" type="text/css"/>
<style>
	.mytable.select td {
		padding-bottom: 0;
	}

	.mytable.select #more_search {
		display: block;
	}

	.table-class tbody td a {
		margin-left: 0;
	}

	.to-fixed {
		position: fixed;
		width: 85.5%;
		top: 50px;
		box-shadow: 0 2px 6px 0 rgba(0, 0, 0, .3);
		z-index: 5;
	}

	.mytable td {
		padding: 10px 0;
	}

	.btn-common-white {
		line-height: 20px;
		outline: none;
		background: white
	}

	.ns-main {
		margin-top: 0;
	}

	.seller_memo {
		background: #FFF9DF !important;
		color: #D09B4C;
	}
</style>
{/block}
<!-- {1block name="thirdmenu"}{/block} -->
<!-- {1block name="warm_prompt"}{/block} -->
<!-- {1block name="right_tab_tip"}{/block} -->
{block name="main"}
<input type="hidden" id="order_id"/>
<input type="hidden" id="print_select_ids"/>
<input type="hidden" id="order_status" value="{$status}"/>
<div>
	<table class="mytable select">
		<tr>
			<th align="left">
				<!--<button onclick="dataExcel()" class="btn-common">导出数据</button>-->

				<!--<a class="btn-common-white" id="PrintOrder" href="javascript:;">-->
				<!--<i class="fa fa-print"></i>-->
				<!--<span>打印订单</span>-->
				<!--</a>-->
			</th>
			<th style="position: relative;">
				<span>下单时间：</span>
				<input type="text" id="startDate" class="input-common middle" placeholder="请选择开始日期"
					   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
				&nbsp;-&nbsp;
				<input type="text" id="endDate" placeholder="请选择结束日期" class="input-common middle"
					   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
				<button class="btn-common-white more-search"><i class="fa fa-chevron-down"></i></button>
				<button onclick="searchData()" class="btn-common">搜索</button>

				<!-- 更多搜索 -->
				<div class="more-search-container">
					<dl>
						<dt>订单编号：</dt>
						<dd>
							<input id="orderNo" class="input-common middle" type="text"/>
						</dd>
					</dl>
					<dl>
						<dt>商户id：</dt>
						<dd>
							<input id="shop_id" class="input-common middle" type="text"/>
						</dd>
					</dl>
					<dl>
						<dt>商户名称：</dt>
						<dd>
							<input id="shop_name" class="input-common middle" type="text"/>
						</dd>
					</dl>
					<dl>
						<dt>状态：</dt>
						<dd>
							<select id="status" class="select-common middle">
								<option value="">全部</option>
								<option value="0">待增加积分，发送消息</option>
								<option value="1">已增加积分，待发送消息</option>
								<option value="2">已增加积分并已发送</option>
								<option value="3">超出时效，不处理</option>
								<option value="4">已增加积分，超出时效不发送消息</option>
							</select>
						</dd>
					</dl>
					<dl>
						<dt></dt>
						<dd>
							<button onclick="searchData()" class="btn-common">搜索</button>
						</dd>
					</dl>
				</div>
			</th>
		</tr>
	</table>

	<table class="table-class" id="ajax-orderlist">
		<thead>
		<tr align="center">
			<th>
				<i class="checkbox-common">
					<input type="checkbox" onclick="CheckAll(this)" id="check"/>
				</i>
			</th>
			<th>订单号</th>
			<th>openid</th>
			<th>商户id/商户名称</th>
			<th>消费金额</th>
			<th>消费时间</th>
			<th>状态</th>
			<th>新增积分</th>
			<th>剩余积分</th>
			<th>推送时间</th>
			<th style="width: 80px;text-align: center">操作</th>
		</tr>
		</thead>
		<tbody id="ajax-orderlist"></tbody>
	</table>
</div>

<div id="orderAction"></div>
<!-- 模态框（Modal） -->
<div class="modal fade hide" id="yhxq" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
	 style="width:700px;left:45%;top:30%;">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>用户详情</h3>
			</div>
			<div class="set-style" id="user_data">
			</div>
			<div class="modal-footer">
				<button class="btn-common-cancle btn-big" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>

{/block}
{block name="script"}

<script type="text/javascript">

	var order_type = '{$order_type}';
	$(window).scroll(function () {
		var scrollTop = $(window).scrollTop();
		if (scrollTop > 140) {
			$("nav.order-nav").addClass("to-fixed").css("width", $(".ns-main").width() - 2);
		} else {
			$("nav.order-nav").removeClass("to-fixed").css("width", "");
		}



	});
	var get_wx_openid = "{:input('param.openid')}";
	// console.log(get_wx_openid);
	function getUserInfo(e) {
		var zhmxurl = "{:__URL('ADMIN_MAIN/member/accountdetail')}";
		var open_id = $(e).attr('data-openid');
		$.get("{:__URL('ADMIN_MAIN/order/getuserinfo','openid=" + open_id + "')}", function (result) {
			var res = result;
			if (res.data != '') {
				var html, is_sub;
				switch (res.data.wx_is_sub) {
					case -1:
						is_sub = '未关注';
						break;
					case 0:
						is_sub = "取消关注";
						break;
					case 1:
						is_sub = "已关注";
						break;
				}
				html = '<dl><dt>会员名:</dt><dd><p><span>' + res.data.user_name + '</span></p></dd></dl>';
				html += '<dl><dt>昵称:</dt><dd><p><span>' + res.data.nick_name + '</span></p></dd></dl>';
				html += '<dl><dt>是否关注:</dt><dd><p><span>' + is_sub + '</span></p></dd></dl>';
				html += '<dl><dt>账户明细:</dt><dd><p><span><a href="' + zhmxurl + '&member_id=' + res.data.uid + '">点击查看</a></span></p></dd></dl>';

			} else {
				html = '<dl><dt></dt><dd><p><span style="color: red">用户未注册</span></p></dd></dl>';
			}
			$("#user_data").html(html);
		}, "json");
		$("#yhxq").modal('show');
	}


	$(function () {
		$("[data-toggle='popover']").popover();
	});

	function searchData() {
		$(".more-search-container").slideUp();
		LoadingInfo(1);
	}

	var is_load_orderaction = 0;

	function LoadingInfo(page_index) {
		var start_date = $("#startDate").val();
		var end_date = $("#endDate").val();
		var order_no = $("#orderNo").val();
		var status = $("#status").val();
		var shop_name = $("#shop_name").val();
		var shop_id = $("#shop_id").val();

		$.ajax({
			type: "post",
			url: "{:__URL('ADMIN_MAIN/order/pushOrderList')}",
			data: {
				"page_index": page_index,
				"page_size": $("#showNumber").val(),
				"start_date": start_date,
				"end_date": end_date,
				"order_no": order_no,
				"status": status,
				"shop_id": shop_id,
				"shop_name": shop_name,
				"wx_openid":get_wx_openid
			},
			success: function (data) {
				//var html = '';
				if (data["data"].length > 0) {

					$("#ajax-orderlist tbody").empty();
					for (var i = 0; i < data["data"].length; i++) {
						var html = '';
						var id = data["data"][i]["id"];// id
						var openid = data["data"][i]["openid"];// 用户openid
						var order_id = data["data"][i]["order_id"];//订单编号
						var shop_name = data["data"][i]["shop_name"];//商户名称
						var shop_id = data["data"][i]["shop_id"];//商户id
						var amount = data["data"][i]["amount"];//商户id
						var time = data["data"][i]["time"];//商户id
						var status = data["data"][i]["status"];//商户id
						var add_points = data["data"][i]["add_points"];//商户id
						var surplus_points = data["data"][i]["surplus_points"];//
						var create_time = timeStampTurnTime(data["data"][i]["create_time"]);//创建时间
						var status_name = '';
						switch (status) {
							case 0:
								status_name = '<span style="color: #bfca17;">待增加积分，发送消息</span>';
								break;
							case 1:
								status_name = '<span style="color:#6dca09;">已增加积分，待发送消息</span>';
								break;
							case 2:
								status_name = '<span style="color: green">已增加积分并已发送</span>';
								break;
							case 3:
								status_name = '<span style="color: red">超出时效，不处理</span>';
								break;
							case 4:
								status_name = '<span style="color: #e05d16">已增加积分，超出时效不发送消息</span>';
								break;
						}
						html += '<tr>';

						html += '<td><i class="checkbox-common"><input id="' + id + '" type="checkbox"  value="' + id + '" name="sub"></i></td>';
						html += '<td><span>' + order_id + '</span></td>';
						html += '<td><span>' + openid + '</span></td>';
						html += '<td><span style="color: #237FE5;">' + shop_id + ' </span> / <span>' + shop_name + '</span></td>';
						html += '<td><span>' + amount + '</span></td>';
						html += '<td><span>' + time + '</span></td>';
						html += '<td>' + status_name + '</td>';
						html += '<td><span>' + add_points + '</span></td>';
						html += '<td><span>' + surplus_points + '</span></td>';
						html += '<td><span>' + create_time + '</span></td>';
						html += '<td><span><a style="color: #237FE5;" href="javascript:;" onclick="getUserInfo(this);" data-openid="' + openid + '">详情</a></span></td>';
						html += '</tr>';


						$("#ajax-orderlist tbody").append(html);
					}
				} else {
					var html = '<tr align="center"><td colspan="10">暂无符合条件的订单</td></tr>';
					$("#ajax-orderlist tbody").html(html);
				}


				initPageData(data["page_count"], data['data'].length, data['total_count']);
				$("#pageNumber").html(pagenumShow(jumpNumber, $("#page_count").val(), {$pageshow}));
			}
		});
	}

	function addmemo(order_id, memo) {
		$("#order_id").val(order_id);
		$("#memo").val(memo);
		$("#Memobox").modal("show");
	}

	/**
	 * 订单数据导出
	 */
	function dataExcel() {
		var start_date = $("#startDate").val();
		var end_date = $("#endDate").val();
		var user_name = $("#userName").val();
		var order_no = $("#orderNo").val();
		var receiver_mobile = $("#receiverMobile").val();
		var order_status = $("#order_status").val();
		var payment_type = $("#payment_type").val();
		var order_ids = new Array();
		$(".table-class tbody input[type = 'checkbox']:checked").each(function () {
			if (!isNaN($(this).val())) {
				order_ids.push($(this).val());
			}
		});
		window.location.href = __URL("ADMIN_MAIN/order/orderDataExcel?start_date=" + start_date + "&end_date=" + end_date + "&user_name=" + user_name + "&order_no=" + order_no + "&order_status=" + order_status + "&receiver_mobile=" + receiver_mobile + "&payment_type=" + payment_type + "&order_ids=" + order_ids.toString());
	}

	/**
	 * 批量删除已关闭订单
	 */
	function batchDelete() {
		var order_ids = new Array();
		$(".table-class tbody input[type = 'checkbox']:checked").each(function () {
			if (!isNaN($(this).val())) {
				order_ids.push($(this).val());
			}
		});
		if (order_ids.length == 0) {
			$("#dialog").dialog({
				buttons: {
					"确定,#0059d6,#fff": function () {
						$(this).dialog('close');
					}
				},
				contentText: "请选择需要操作的记录",
				title: "消息提醒",
			});
			return false;
		}
		delete_order(order_ids);
	}

	// 点击显示更多搜索
	$(".more-search").on("click", function (e) {
		$(".more-search-container").slideToggle();
		$(document).one("click", function () {
			$(".more-search-container").slideUp();
		});
		e.stopPropagation();
	})

	$(".more-search-container").on("click", function (e) {
		e.stopPropagation();
	});
</script>
{/block}